package file.day9_22;

public class DaemonTreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread(){
            public void run(){
                for (int i = 0; i < 5; i++) {
                    System.out.println("rose:let me go!");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("rose:啊啊啊");
                System.out.println("落水声");
            }
        };

        Thread jack = new Thread(){
            public void run(){
                int i = 0;
                while (true){
                    System.out.println("jack:You jump,i jump");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };


        rose.start();
        jack.setDaemon(true);//将jack这个线程变为守护线程，
        // 此时普通线程就只有rose这一个，rose一旦结束，jack就会被杀死
        jack.start();


    }
}
